home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Jotto2.so Folder / Jotto ][ ƒ / MSG Shell ƒ / msg apple events.c next >
Encoding:
C/C++ Source or Header  |  1994-05-10  |  3.7 KB  |  138 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg apple events.c
  4.  
  5. Purpose:    This module handles the 4 required apple events: open
  6.             application, open document, print document (not supported),
  7.             and quit application.
  8.  
  9.  
  10. Jotto ][ -=- a simple word game, revisited
  11. Copyright (C) 1993 Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "msg apple events.h"
  31. #include "msg environment.h"
  32. #include "jotto generic open.h"
  33. #include "jotto.h"
  34.  
  35.  
  36. void SetUpAppleEvents(void)
  37. {
  38.     AEEventHandlerUPP gHandleOpenAppAERD = NewAEEventHandlerProc(HandleOpenAppAE);
  39.     AEEventHandlerUPP gHandleOpenDocAERD = NewAEEventHandlerProc(HandleOpenDocAE);
  40.     AEEventHandlerUPP gHandlePrintDocAERD = NewAEEventHandlerProc(HandlePrintDocAE);
  41.     AEEventHandlerUPP gHandleQuitAERD = NewAEEventHandlerProc(HandleQuitAE);
  42.  
  43.     AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
  44.                                     gHandleOpenAppAERD, 0, FALSE);
  45.     AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
  46.                                     gHandleOpenDocAERD, 0, FALSE);
  47.     AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
  48.                                     gHandlePrintDocAERD, 0, FALSE);
  49.     AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
  50.                                     gHandleQuitAERD, 0, FALSE);
  51.     AESetInteractionAllowed(kAEInteractWithAll);
  52. }
  53.  
  54. pascal OSErr HandleOpenAppAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  55.     long refcon)
  56. {
  57.     NewGame();
  58.     return MyGotRequiredParams(theAppleEvent);
  59. }
  60.  
  61. pascal OSErr HandleOpenDocAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  62.     long refcon)
  63. {
  64.     OSErr            isHuman, dummy;
  65.     FSSpec            myFSS;
  66.     AEDescList        docList;
  67.     long            index, itemsInList;
  68.     Size            actualSize;
  69.     AEKeyword        keywd;
  70.     DescType        returnedType;
  71.     
  72.     isHuman=AEGetParamDesc(reply, keyDirectObject, typeAEList, &docList);
  73.     if (isHuman==noErr)
  74.     {
  75.         if (MyGotRequiredParams(reply)==noErr)
  76.         {
  77.             if (AECountItems(&docList, &itemsInList)==noErr)
  78.             {
  79.                 for (index=1; index<=itemsInList; index++)
  80.                 {
  81.                     if (AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType,
  82.                         &myFSS, sizeof(myFSS), &actualSize)==noErr)
  83.                     {
  84.                         GenericOpen(&myFSS);
  85.                     }
  86.                     else
  87.                     {
  88.                         // handle error getting Nth pointer
  89.                     }
  90.                 }
  91.             }
  92.             else
  93.             {
  94.                 // handle error counting items
  95.             }
  96.         }
  97.         else
  98.         {
  99.             // handle error from MyGetRequiredParams
  100.             dummy=AEDisposeDesc(&docList);
  101.         }
  102.     }
  103.     else
  104.     {
  105.         // handle error getting direct parameter
  106.     }
  107.     
  108.     return isHuman;
  109. }
  110.  
  111. pascal OSErr HandlePrintDocAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  112.     long refcon)
  113. {
  114.     return errAEEventNotHandled;
  115. }
  116.  
  117. pascal OSErr HandleQuitAE(const AppleEvent *theAppleEvent, const AppleEvent *reply,
  118.     long refcon)
  119. {
  120.     OSErr            isHuman;
  121.     
  122.     isHuman=MyGotRequiredParams(reply);
  123.     if (isHuman==noErr)
  124.         gDone = 1;
  125.     
  126.     return isHuman;
  127. }
  128.  
  129. pascal OSErr MyGotRequiredParams(const AppleEvent *theAppleEvent)
  130. {
  131.     DescType        returnedType;
  132.     Size            actualSize;
  133.     
  134.     return (AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard,
  135.             &returnedType, 0L, 0, &actualSize)==errAEDescNotFound) ? noErr :
  136.             errAEParamMissed;
  137. }
  138.